package com.dk.controller;

import com.dk.pojo.Role;
import com.dk.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("role")

public class RoleController {
    @Autowired
    private RoleService roleService;

    @RequestMapping("toshow")
    public String toshow() {
        return "role/show";

    }

    @RequestMapping("getInfo")
    @ResponseBody
    public List<Role> getInfo() {
        List<Role> list = roleService.selectInfo();
        return list;
    }

    @RequestMapping("addInfo")
    public String addInfo() {
        return "role/add";
    }

    @RequestMapping("insertinto")
    @ResponseBody
    public boolean insertinto(Role role, @RequestParam("mids") Integer[] mids) {
        boolean a = roleService.insertinto(role, mids);
        return a;

    }

    @RequestMapping("huixuan")
    public String huixuan(Integer rid, Model mo) {
        Role r = roleService.selectByid(rid);
        mo.addAttribute("r", r);
        return "role/update";
    }

    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updateInfo(Integer[] mids, Role r) {
        boolean a = roleService.updateInfo(mids, r);
        return a;
    }

    @RequestMapping("roledelete")
    @ResponseBody
    public boolean roledelete(Integer rid) {
        boolean a = roleService.deleteById(rid);
        return a;
    }
}
